{% extends "tabs-base.html" %}

{% block tabs %}
    {{ make_tab('detail', 'fa-info-circle', url('contest_view', contest.key), _('Info')) }}
    {% if contest.ended or can_edit %}
        {{ make_tab('stats', 'fa-pie-chart', url('contest_stats', contest.key), _('Statistics')) }}
    {% endif %}

    {% if contest.start_time <= now or perms.judge.see_private_contest %}
        {% if contest.can_see_own_scoreboard(request.user) %}
            {{ make_tab('ranking', 'fa-bar-chart', url('contest_ranking', contest.key), _('Rankings')) }}
            {% if request.user.is_authenticated %}
                {{ make_tab('participation', 'fa-users', url('contest_participation_own', contest.key), _('Participation')) }}
            {% endif %}
        {% else %}
            {{ make_tab('ranking', 'fa-bar-chart', None, _('Hidden Rankings')) }}
        {% endif %}
    {% endif %}
    {% if can_edit %}
        {% if perms.judge.moss_contest and has_moss_api_key %}
            {{ make_tab('moss', 'fa-gavel', url('contest_moss', contest.key), _('MOSS')) }}
        {% endif %}
        {{ make_tab('edit', 'fa-edit', url('admin:judge_contest_change', contest.id), _('Edit')) }}
    {% endif %}
    {% if perms.judge.clone_contest %}
        {{ make_tab('clone', 'fa-copy', url('contest_clone', contest.key), _('Clone')) }}
    {% endif %}

    {% if request.user.is_authenticated %}
        {% if contest.started or is_editor or is_tester %}
            {% set in_contest = contest.is_in_contest(request.user) %}
            {% if contest.ended %}
                {# Allow users to leave the virtual contest #}
                {% if in_contest %}
                    <form action="{{ url('contest_leave', contest.key) }}" method="post"
                          class="contest-join-pseudotab unselectable button">
                        {% csrf_token %}
                        <input type="submit" class="leaving-forever" value="{{ _('Leave contest') }}">
                    </form>
                {% else %}
                    {# Allow users to virtual join #}
                    <form action="{{ url('contest_join', contest.key) }}" method="post"
                          class="contest-join-pseudotab unselectable button">
                        {% csrf_token %}
                        <input type="submit" value="{{ _('Virtual join') }}" class="contest-join">
                    </form>
                {% endif %}
            {% else %}
                {# Allow users to leave the contest #}
                {% if in_contest %}
                    <form action="{{ url('contest_leave', contest.key) }}" method="post"
                          class="contest-join-pseudotab unselectable button">
                        {% csrf_token %}
                        <input type="submit" value="
                            {%- if request.participation.spectate %}
                                {{- _('Stop spectating') -}}
                            {% else %}
                                {{- _('Leave contest') -}}
                            {% endif %}">
                    </form>
                {% elif contest.is_live_joinable_by(request.user) %}
                    <form action="{{ url('contest_join', contest.key) }}" method="post"
                          class="contest-join-pseudotab unselectable button">
                        {% csrf_token %}
                        <input type="submit"
                               class="contest-join{% if not has_joined %} first-join{% endif %}"
                               value="{{ _('Join contest') }}">
                    </form>
                {% elif contest.is_spectatable_by(request.user) %}
                    <form action="{{ url('contest_join', contest.key) }}" method="post"
                          class="contest-join-pseudotab unselectable button">
                        {% csrf_token %}
                        <input type="submit" value="{{ _('Spectate contest') }}" class="contest-join">
                    </form>
                {% else %}
                    <form action="{{ url('contest_join', contest.key) }}" method="post"
                          class="contest-join-pseudotab unselectable button disabled">
                        {% csrf_token %}
                        <input type="submit" class="disabled"
                               title="{{ _('You cannot join this contest.') }}"
                               value="{{ _('Join contest') }}" disabled>
                    </form>
                {% endif %}
            {% endif %}
        {% endif %}
    {% elif contest.started %}
        <form action="{{ url('auth_login') }}" method="get"
              class="contest-join-pseudotab unselectable button">
            <input type="hidden" name="next" value="{{ LOGIN_RETURN_PATH|urlencode }}">
            <input type="submit" value="{{ _('Log in to participate') }}">
        </form>
    {% endif %}
{% endblock %}
